Skip to main content

The Wilson score interval and weighted histograms

programming
statistics
Published

May 7, 2021

The Wilson Score interval (WSI) has won the LHCb internal challenge for the most suitable interval for efficiencies. The question is what to do when events are weighted was left open at the time. It is addressed here, the WSI can be used also with weighted histograms if ordinary counts in unweighted histograms are replaced with effective counts in weighted histograms.

The Wilson score interval is given by, see e.g. https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval: \[ p_\text{min} = \frac{n_S + \frac 12 z^2}{n_S + n_F + z^2} - \frac{z}{n_S + n_F + z^2} \sqrt{\frac{n_S n_F}{n_S + n_F} + \frac{z^2}{4}} \] \[ p_\text{max} = \frac{n_S + \frac 12 z^2}{n_S + n_F + z^2} + \frac{z}{n_S + n_F + z^2} \sqrt{\frac{n_S n_F}{n_S + n_F} + \frac{z^2}{4}} \] with \(n_S\) counts of selected events, \(n_F\) counts of rejected events, \(z\) number of sigmas (\(z = 1\) for standard intervals).

In case of weighted events, the \(n_S,n_F\) are the effective counts, computed as \[ n_\text{effective} = \frac{\big(\sum_i w_i\big)^2}{\sum_i w^2_i}. \]

In boost-histogram, this is computed as n_eff = h.values() ** 2 / h.variances() for a histogram h with WeightedSum storage. Since we look into a single bin here, we skip the histogram and just use the WeightedSum() accumulator directly, which is one element of the storage.

(WeightedSum(value=29.7824, variance=357.384),
 WeightedSum(value=1008.21, variance=25830.4))
efficiency = 0.06 - 0.03 + 0.05

Note that the error is asymmetric in general. This is especially noticable when p is close to 0 or 1.

Let’s check with a parametric bootstrap simulation whether this uncertainty is correct. It is parametric because we know that the weights are exponentially distributed.

efficiency = 0.06 - 0.03 + 0.05
efficiency(boot) = 0.06 - 0.03 + 0.03

Ok, check passed.